package com.winit.generator.task;

import com.winit.generator.config.Configuration;
import com.winit.generator.framework.AbstractApplicationTask;
import com.winit.generator.framework.context.ApplicationContext;
import com.winit.generator.handler.BaseHandler;
import com.winit.generator.handler.impl.CoreHandler;
import com.winit.generator.model.DaoInfo;

import java.util.List;

public class CoreTask extends AbstractApplicationTask {

//    private static String CORE_FTL = "template/Core.ftl";
    private static String CORE_FTL = Configuration.CONFIG_FILE_NAME.equals("configuration_mrp.xml") ? "template/Core.ftl" : "template/Core_member.ftl";

    private List<DaoInfo> daoInfos;

    @SuppressWarnings("unchecked")
    @Override
    protected boolean doInternal(ApplicationContext context) {
        logger.info("开始生成Core");

        daoInfos = (List<DaoInfo>) context.getAttribute("daoList");

        BaseHandler<DaoInfo> handler = null;
        for (DaoInfo daoInfo : daoInfos) {
            handler = new CoreHandler(CORE_FTL, daoInfo);
            handler.execute(context);
        }

        logger.info("生成dao完成");
        return false;
    }

    @Override
    protected void doAfter(ApplicationContext context) throws Exception {
    }

}
